package Code

//Given an array of integers, return indices of the two numbers such that they add up to a specific target.
//
//You may assume that each input would have exactly one solution, and you may not use the same element twice.
//
//Example:
//
//Given nums = [2,  11, 15,7], target = 9,
//
//Because nums[0] + nums[1] = 2 + 7 = 9,
//return [0, 1]
//nums := [4]int{11, 2, 7, 3}
func TwoSum(nums []int,target int) (int, int) {

	for i := 0; i < len(nums); i++ {
		for j := i + 1; j < len(nums); j++ {
			if nums[i]+nums[j] == target {
				return i, j
			}
		}
	}
	return -1,-1
}
func TwoSum1(nums []int, target int) []int {
	m := make(map[int]int)
	for k, v := range nums {
		if idx, ok := m[target-v]; ok {
			return []int{idx, k}
		}
		m[v] = k
	}
	return nil
}